import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../../global/extension/int_extension.dart';
import '../../../global/provider/filter_provider.dart';
import '../../../../generated/l10n.dart';

class YSHFilterPageContent extends StatelessWidget {
  const YSHFilterPageContent({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [_setupYourChioce(context), _setupChioceSelect()],
    );
  }

  Widget _setupYourChioce(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(16.px),
      alignment: Alignment.center,
      child: Text(
        S.of(context).filterPageContentTitle,
        style: Theme.of(context)
            .textTheme
            .titleLarge
            ?.copyWith(fontWeight: FontWeight.bold),
      ),
    );
  }

  Widget _setupChioceSelect() {
    return Expanded(
      child: Consumer<YSHFilterProvider>(
        builder: (ctx, filterProvider, child) {
          return ListView(children: [
            _setupChioceSelectCell(
                S.current.filterPageContentOption_1,
                S.current.filterPageContentOptionDetail_1,
                filterProvider.isGlutenFree, (value) {
              filterProvider.isGlutenFree = value;
            }),
            _setupChioceSelectCell(
                S.current.filterPageContentOption_2,
                S.current.filterPageContentOptionDetail_2,
                filterProvider.isLactoseFree, (value) {
              filterProvider.isLactoseFree = value;
            }),
            _setupChioceSelectCell(
                S.current.filterPageContentOption_3,
                S.current.filterPageContentOptionDetail_3,
                filterProvider.isVegetarian, (value) {
              filterProvider.isVegetarian = value;
            }),
            _setupChioceSelectCell(
                S.current.filterPageContentOption_4,
                S.current.filterPageContentOptionDetail_4,
                filterProvider.isVegan, (value) {
              filterProvider.isVegan = value;
            })
          ]);
        },
      ),
    );
  }

  Widget _setupChioceSelectCell(String title, String subtitle, bool value,
      void Function(bool value) onChanged) {
    return ListTile(
        title: Text(title),
        subtitle: Text(subtitle),
        trailing: Switch(value: value, onChanged: onChanged));
  }
}
